export default {
	// 获取微信授权回调url
	        getRedirectUri(url) {
	          url = url || window.location.href;
	          const pos = url.indexOf('?');
	          if (pos > -1) {
	            return encodeURIComponent(url.substring(0, pos));
	          }
	          return encodeURIComponent(url);
	        },
	        // 解析url参数
	        getUrlParam(name) {
	          const reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)');
	          const r = window.location.search.substr(1).match(reg);
			  // alert( window.location.search)
	          if (r != null) return decodeURIComponent(r[2]);
	          return null;
	        },
	
	        // 初始化
	        init(data) {
	          const code = this.getUrlParam('login_code');
			  let loCode = localStorage.getItem('lo_code')
	          if (!code || loCode == code) {
	            this.auth(data);
	            return null;
	          }	
			  localStorage.setItem('lo_code', code)
			// debugger
	          return code;
	        },
	
	        // 微信授权
	        async auth() {
				console.log(123321)
				let href = window.location.href.split("?")[0]
	          let data = {
	          	payload:encodeURIComponent(JSON.stringify({
					page: href,
					event: 'login',
				})),
	          	platform: 'WechatOfficialAccount'
	          }
	          let res = await uni.request({
	          	header: {
	          	},
	          	url: 'https://door.10906.cn/api/' + 'third/wechat/oauthLogin',
	          	method: 'POST',
	          	data
	          })
			  console.log(data)
			 
	          window.location.replace(res.data.data.login_url);
	        },
	
	        // 是否为微信内置浏览器
	        isWeixin() {
	          return (
	            typeof WeixinJSBridge === 'object' &&
	            typeof WeixinJSBridge.invoke === 'function'
	          );
	        },
	
	        // 关闭当前微信浏览器窗口
	        closeWindow() {
	          if (typeof WeixinJSBridge !== 'undefined') {
	            try {
	              WeixinJSBridge.call('closeWindow');
	            } catch (error) {
	              console.error('Failed to close WeChat window:', error);
	            }
	          }
	        },
}